﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Moving03.Classes;

namespace Moving03
{
    public partial class WebForm12 : BasePage
    {
        DataClasses1DataContext context = new DataClasses1DataContext();
        int stt = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            int mavc = int.Parse(Request.QueryString["mavc"]);
            var query = from ddcn in context.DiaDiemCapNhats
                        join dd in context.DuongDis on ddcn.Id_DDCapNHat equals dd.Id_DDCapNhat
                        where ddcn.Id_ThongTinVanChuyen == mavc
                        orderby dd.SoThuTu
                        select dd;
            Panel1.Controls.Add(new LiteralControl("<table  border='0'  width='100%' cellpadding='0' cellspacing='1'>"));
            Panel1.Controls.Add(new LiteralControl("<tr bgcolor='#507DD2' style='color: #FFFFFF; font-size:14px; height:40px' align='center' >"));
            Panel1.Controls.Add(new LiteralControl("<th>STT</th>"));
            Panel1.Controls.Add(new LiteralControl("<th>Đã đến</th>"));
            Panel1.Controls.Add(new LiteralControl("<th>Mã Id</th>"));
            Panel1.Controls.Add(new LiteralControl("<th>Nơi tới</th>"));
            Panel1.Controls.Add(new LiteralControl("<th>Ngày tới</th>"));
            Panel1.Controls.Add(new LiteralControl("</tr>"));
            foreach (var i in query)
            {
                var query2 = (from ddtg in context.DiaDiemTrungGians
                              where ddtg.Id_DDTrungGian == i.Id_DDTGian
                              select ddtg).Single();

                Panel1.Controls.Add(new LiteralControl("<tr style='height:30px'>"));
                Panel1.Controls.Add(new LiteralControl("<td>" + stt));
                Panel1.Controls.Add(new LiteralControl("</td>"));
                Panel1.Controls.Add(new LiteralControl("<td>"));
                CheckBox ckbox = new CheckBox();
                ckbox.ID = "ckbox_" + stt.ToString();
                if (i.DaToiChua == 1)
                    ckbox.Checked = true;
                ckbox.Enabled = false;
                   
                Panel1.Controls.Add(ckbox);
                Panel1.Controls.Add(new LiteralControl("</td>"));
                Panel1.Controls.Add(new LiteralControl("<td>"));
                Label lb = new Label();
                lb.ID = "lb_" + stt.ToString();
                lb.Text = i.Id_DuongDi.ToString();
                Panel1.Controls.Add(lb);
                Panel1.Controls.Add(new LiteralControl("</td>"));
                Panel1.Controls.Add(new LiteralControl("<td>" + query2.TenDiaDiem));
                Panel1.Controls.Add(new LiteralControl("</td>"));
                Panel1.Controls.Add(new LiteralControl("</td>"));
                Panel1.Controls.Add(new LiteralControl("<td>" + i.NgayDen.ToString()));
                Panel1.Controls.Add(new LiteralControl("</td>"));
                Panel1.Controls.Add(new LiteralControl("</tr>"));
                stt++;

            }
            Panel1.Controls.Add(new LiteralControl("</table>"));

            string s =  returnTongTien(mavc).ToString();

            
            Label1.Text = returnTongTien(mavc).ToString();
            Label2.Text = returnNgayToi(mavc);
            int daThanhToan = TinhTrangThanhToan(mavc);
            if (daThanhToan == 1)
                Label3.Text = "Đã Thanh Toán";
            else
                Label3.Text = "Chưa Thanh Toán";
        }
     
        public string returnNgayToi(int mavc)
        {
            var ttvc1 = context.ThongTinVanChuyens.Single(p => p.Id_TTVC == mavc);
            return ttvc1.NgayToi.ToString();
        }
        public string returnTongTien(int mavc)
        {
            var ttvc1 = context.ThongTinVanChuyens.Single(p => p.Id_TTVC == mavc);
            return ttvc1.TongTien.ToString();
        }
        public int TinhTrangThanhToan(int mavc)
        {
            var ttvc1 = context.ThongTinVanChuyens.Single(p => p.Id_TTVC == mavc);
            return (int)ttvc1.DaThanhToan;
        }
    }

}